import json
import pathlib
from typing import Any, Dict

import yaml  # pip install pyyaml

class ConfigError(Exception):
    pass

def load_config(path: str | pathlib.Path) -> Dict[str, Any]:
    path = pathlib.Path(path)
    if not path.exists():
        raise ConfigError(f"Config file not found: {path}")

    with path.open("r", encoding="utf-8") as fh:
        if path.suffix in {".yaml", ".yml"}:
            data = yaml.safe_load(fh)
        elif path.suffix == ".json":
            data = json.load(fh)
        else:
            raise ConfigError(f"Unsupported config format: {path.suffix}")

    if not isinstance(data, dict):
        raise ConfigError("Top-level config must be a dictionary")

    return data
